<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png" />
    <button @click="showModal">点我</button>
    <el-date-picker
      v-model="selectedDate"
      :format="dateFormat"
      :picker-options="pickerOptions"
      type="date"
    ></el-date-picker>
  </div>
</template>

<script>
// @ is an alias to /src
import showMsg from "@/components/showMsg";
import axios from "axios";
import cheerio from "cheerio";
export default {
  name: "HomeView",
  components: {},
  data() {
    return {
      selectedDate: null,
      dateFormat: "MMM.DD,YYYY",
      pickerOptions: {
        i18n: {
          month: {
            // 设置月份的缩写为英文
            jan: "Jan",
            feb: "Feb",
            mar: "Mar",
            apr: "Apr",
            may: "May",
            jun: "Jun",
            jul: "Jul",
            aug: "Aug",
            sep: "Sep",
            oct: "Oct",
            nov: "Nov",
            dec: "Dec",
          },
        },
      },
    };
  },
  watch: {
    selectedDate(v) {
      console.log(v, "v");
    },
  },
  async created() {
    console.log("created");
    /*this.callUniCloudFunction({
      bookName: "Vue.js",
      author: "尤雨溪",
      intro: "Vue.js 是一套构建用户界面的渐进式框架",
      orgin: "xxx",
    });
    return; */
    const config = {
      headers: {
        "Content-Type": "application/json",
      },
    };

    // 请求体数据
    const data = {
      text: "ﺭﯗﺳﯩﻴﻪﺩﯨﻜﻰ ﺑﯩﺮ ﻣﯘﮪﯩﻢ ﺋﺎﻗﯩﻠﻼﺭ ﺋﺎﻣﺒﯩﺮﯨﻨﯩﯔ ﻣﯚﻟﭽﻪﺭﻟﯩﺸﯩﭽﻪ، ﺭﯗﺳﯩﻴﻪﻧﯩﯔ ﺋﯘﺭﯗﺵ ﻣﻪﺯﮔﯩﻠﯩﺪﯨﻜﻰ ﺋﯩﻘﺘﯩﺴﺎﺩﻯ ﻳﻪﻧﯩﻼ ﺋﯧﺸﯩﺸﻰ ﻣﯘﻣﻜﯩﻦ ﺋﯩﻜﻪﻥ، ﻟﯧﻜﯩﻦ ﺑﯘ ﻳﯩﻠﻨﯩﯔ ﻛﯧﻴﯩﻨﻜﻰ ﻳﯧﺮﯨﻤﯩﺪﺍ ﻣﻪﺳﯩﻠﯩﮕﻪ ﺩﯗﭺ ﻛﯧﻠﯩﺸﻰ ﻣﯘﻣﻜﯩﻦ ﺋﯩﻜﻪﻥ. ﭘﯘﺗﯩﻨﻨﯩﯔ ﺋﻮﻛﺮﺍﺋﯩﻨﺎﻏﺎ ﺋﻮﻣﯘﻣﻴﯜﺯﻟﯜﻙ ﺗﺎﺟﺎﯞﯗﺯ ﻗﯩﻠﯩﺸﻰ ﺟﺎﺯﺍﻻﻧﻐﺎﻥ، ﺑﯘ ﺩﺍﯞﺍﻟﻐﯘﺵ ﭘﻪﻳﺪﺍ ﻗﯩﻠﻐﺎﻥ، ﺋﻪﻣﻤﺎ ﺭﯗﺳﯩﻴﻪ ﺋﯩﻘﺘﯩﺴﺎﺩﯨﻨﯩﯔ ﯞﻩﻳﺮﺍﻥ ﺑﻮﻟﯘﺷﯩﻨﻰ ﻛﻪﻟﺘﯜﺭﯛﭖ ﭼﯩﻘﺎﺭﻣﯩﻐﺎﻥ، ﭼﯜﻧﻜﻰ ﺭﯗﺳﯩﻴﻪ ﮪﻪﺭﺑﯩﻲ ﺧﯩﺮﺍﺟﻪﺗﻨﻰ ﻛﯚﭘﻪﻳﺘﻜﻪﻥ، ﮪﻪﻣﺪﻩ ﺑﺎﺷﻘﺎ ﺳﻮﺩﺍ ﮪﻪﻣﺮﺍﮪﻠﯩﺮﯨﻐﺎ ﺋﯚﺯﯨﻨﯩﯔ ﺗﺎﯞﺍﺭﻟﯩﺮﯨﻨﻰ ﺳﯧﺘﯩﺸﻘﺎ ﻳﯜﺯﻟﻪﻧﮕﻪﻥ. ﻟﯧﻜﯩﻦ، ﻳﯘﻗﯩﺮﻯ ﮪﻪﺭﺑﯩﻲ ﺧﯩﺮﺍﺟﻪﺕ ﭼﯩﻘﯩﻤﻰ ﺑﯘ ﻳﯩﻠﻘﻰ ﺋﻮﻣﯘﻣﯩﻲ ﭼﯩﻘﯩﻤﻨﯩﯔ ﺋﯜﭼﺘﯩﻦ ﺑﯩﺮ ﻗﯩﺴﻤﯩﻨﻰ ﻳﻪﻧﻰ %29ﯨﻨﻰ ﺋﯩﮕﯩﻠﯩﮕﻪﻥ، ﺷﯘﻧﯩﯔ ﺑﯩﻠﻪﻥ ﺑﯩﺮ ﯞﺍﻗﯩﺘﺘﺎ، ﺋﯩﻘﺘﯩﺴﺎﺩﺗﺎ ﺑﻪﻙ ﻗﯩﺰﯨﭗ ﻛﯧﺘﯩﺸﻨﯩﯔ ﺋﯩﻜﻜﻰ ﻛﯚﺭﺳﻪﺗﻜﯜﭼﻰ ﭘﯘﻝ ﭘﺎﺧﺎﻟﻠﯩﻘﻰ ﯞﻩ ﺋﯩﺸﭽﯩﻼﺭ ﻗﯩﺴﻠﯩﻘﻰ ﻛﯚﺭﯛﻟﮕﻪﻥ، ﻛﯧﻴﯩﻨﻜﯩﺴﻰ ﺋﯩﺨﺘﯩﺴﺎﺳﻠﯩﻘﻼﺭﻧﯩﯔ ﺋﯧﻘﯩﭗ ﻛﯧﺘﯩﺸﻰ ﺗﯜﭘﻪﻳﻠﯩﺪﯨﻦ ﭘﻪﻳﺪﺍ ﺑﻮﻟﻐﺎﻥ، ﮪﺎﺯﯨﺮﺩﯨﻦ ﺑﺎﺷﻼﭖ 2025-ﻳﯩﻠﯩﻐﯩﭽﻪ ﻣﻪﺯﻛﯘﺭ ﺩﯙﻟﻪﺗﻨﯩﯔ ﺋﯩﻘﺘﯩﺴﺎﺩﯨﺪﺍ ﻛﯚﺭﯛﻟﯜﺵ ﺋﯧﮭﺘﯩﻤﺎﻟﻰ ﺑﻮﻟﻐﺎﻥ ﺋﻪﮪﯟﺍﻟﻼﺭﻧﻰ ﺋﯧﻼﻥ ﻗﯩﻠﯩﻨﻐﺎﻥ.",
      src_from: "ug",
    };
    /*   const formData = new FormData();
    formData.append("text", data.text);
    formData.append("src_from", data.src_from); */
    // 发送POST请求
    axios
      .post("/text_to_voice", data, config)
      .then((response) => {
        // 请求成功后的处理
        console.log("Response:", response.data);
      })
      .catch((error) => {
        if (error.response) {
          // 请求已发出，但服务器响应的状态码不在 2xx 范围内
          console.log("Error Response:", error.response);
          console.log("Error Status:", error.response.status);
          console.log("Error Data:", error.response.data);
        } else if (error.request) {
          // 已经完成请求，但没有收到响应
          console.log("Error Request:", error.request);
        } else {
          // 发送请求时发生了错误
          console.log("Error Message:", error.message);
        }
        console.log("Error Config:", error.config);
      });
  },
  methods: {
    showModal() {
      showMsg("Hello, Vue 2 with JSX!", (close) => {
        console.log("点确定了");
        close();
      });
    },
    async callUniCloudFunction(data) {
      const functionName = "baiduReading"; // 替换为你的云函数名
      const baseUrl =
        "https://fc-mp-95c866d2-f879-49d1-81b9-75408831d680.next.bspapp.com/"; // 替换为你的环境ID
      const url = `${baseUrl}${functionName}`;

      try {
        console.log(
          `开始调用云函数传入参数----",
       书名:${data.bookName}-----
       作者:${data.author}-----
       简介:${data.intro}-----
       段落:${data.orgin},-----
       -----------`
        );
        const postConfig = {
          headers: {
            "Content-Type": "application/json",
            // Add any other headers if needed
          },
        };
        const response = await axios.post(url, data, postConfig);
        if (!response.data.success) {
          console.error("云函数调用失败:", response.data);
          return {
            success: false,
            message: response.data.error,
          };
        }
        return {
          success: true,
          message: response.data.message,
        };
      } catch (error) {
        console.error(
          "调用云函数时发生错误:",
          error.response ? error.response.data : error.message
        );
      }
    },
  },
};
</script>
